/**
 * Copyright © 2014 TingerSure. All rights reserved.
 */
package org.sure.scomet.util;

import java.io.IOException;
import java.util.Properties;

/**
 * This is the configuration file management class, which is responsible for
 * providing information about the configuration files to other classes.
 * 
 * @author TingerSure
 * 
 */
public class ConfigManager {

	/**
	 * the configuration properties
	 */
	private static Properties configs = null;

	/**
	 * Destroy the configuration properties,it does nothing.
	 */
	public static void destroy() {

	}

	/**
	 * Get the configuration value by a key from the properties file.
	 * 
	 * @param key
	 *            a configuration key
	 * @param defaultValue
	 *            the default value
	 * @return the value corresponding to the key
	 */

	public static String getConfig(String key, String defaultValue) {
		if (configs == null) {
			return defaultValue;
		}
		return configs.getProperty(key, defaultValue);
	}

	/**
	 * Initialize configuration properties by the configuration file.
	 */
	public static void init() {
		configs = new Properties();
		try {
			configs.load(ConfigManager.class
					.getResourceAsStream("/scomet.properties"));
		} catch (IOException e) {
			configs = null;
		} catch (NullPointerException e) {
			configs = null;
		}
	}
}
